{
  "properties" : { },
  "id" : "2416028eb77a4ebe89bfcdb257026067",
  "script" : null,
  "groupId" : "9c800c558ce64f189f6fb4c3df44bc9f",
  "name" : "历史告警导出",
  "createTime" : 1727070892235,
  "updateTime" : 1726823806191,
  "lock" : "1",
  "createBy" : "ndmp",
  "updateBy" : "ndmp",
  "path" : "historyExport",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "{\r\n    \"alarmTypeName\": \"\",\r\n    \"deptName\": \"\",\r\n    \"dateTime\": \"\",\r\n    \"alarmContent\": \"\",\r\n    \"deviceName\": \"\",\r\n    \"alarmMetric\": \"\",\r\n    \"levelId\": 0,\r\n    \"alarmStrategy\": \"\",\r\n    \"alarmTarget\": \"\",\r\n    \"alarmTime\": null,\r\n    \"deviceType\": 0,\r\n    \"needCalculate\": true,\r\n    \"id\": \"\"\r\n}",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : null,
  "description" : "",
  "requestBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "alarmTypeName",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "deptName",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "dateTime",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "alarmContent",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "deviceName",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "alarmMetric",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "levelId",
      "value" : "0",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "alarmStrategy",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "alarmTarget",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "alarmTime",
      "value" : "null",
      "description" : "",
      "required" : false,
      "dataType" : "Object",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "deviceType",
      "value" : "0",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "needCalculate",
      "value" : "true",
      "description" : "",
      "required" : false,
      "dataType" : "Boolean",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "id",
      "value" : "8b81a7bb9a949707cda13ebb166f314c,1830547553570131968",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  },
  "responseBodyDefinition" : null
}
================================
import org.springblade.core.tool.utils.Func;
import com.kd.ndmp.core.excel.AlarmWebsocketData;
import java.net.URLEncoder;
import com.alibaba.excel.EasyExcel;
import response;
import org.springframework.beans.BeanUtils;
import java.time.LocalDateTime;
import cn.hutool.core.util.StrUtil

List idList;
if(body.id != null && body.id != '') {
    idList = Func.toStrList(body.id);
}
sql = """
    select info.*, dev.device_name,dev.ip,
    CASE WHEN dev.device_type = 1 THEN '路由器' WHEN dev.device_type = 2 THEN '交换机' END AS alarm_type_name,
    CASE WHEN info.is_recovery = 0 THEN '未恢复' WHEN info.is_recovery = 1 THEN '已恢复' END AS is_recovery_str,
    ty.type_name, met.metirc_name alarm_metric,
    leve.level, leve.level_name, leve.display_color, grou.id dept_id,grou.group_name dept_name
    from alarm_info_history info 
    left join ndmp_device dev on dev.ID = info.alarm_target
    left join alarm_rule ru on ru.id = info.alarm_rule_id
    left join alarm_metric met on met.id = ru.rule_metric_id
    left join alarm_type ty on ty.id = met.metirc_type_id
    left join alarm_level leve on leve.level = ru.level
    left join NDMP_GROUP_DEVICE_RELATION rel on rel.device_id = dev.id
    left join NDMP_GROUP grou on grou.id = rel.group_id
    <where>
        <if test="idList != null and idList.size() > 0">
        and info.id in
        <foreach item="item" index="index" collection="idList" open="(" separator="," close=")">
            #{item}
        </foreach>
    </if>
    </where>
"""

List alarminfoVOS = db.select(sql);
List res = new ArrayList();
for (item in alarminfoVOS) {
    AlarmWebsocketData vo = new AlarmWebsocketData();
    vo.alarmTarget = item.deviceName;
    vo.alarmTypeName = item.typeName;
    vo.alarmMetric = item.alarmMetric;
    vo.alarmContent = item.alarmContent;
    vo.levelName = item.levelName;
    vo.deptName = item.deptName;
    vo.alarmStateStr = "已确认";
    vo.ip = item.ip;
    vo.isRecoveryStr = item.isRecoveryStr;
    vo.confirmPerson = item.confirmPerson;
    if (item.confirmTime != null){
        vo.confirmTime = (item.confirmTime).toLocalDateTime();
    }
    vo.alarmTime = (item.alarmTime).toLocalDateTime();
    vo.firstAlarmTime = (item.firstAlarmTime).toLocalDateTime();
    vo.alarmCount = item.alarmCount::int;
    if (item.recoveryTime != null){
        vo.recoveryTime = (item.recoveryTime).toLocalDateTime(); 
    }
    res.add(vo);
}
var fileName = URLEncoder.encode("历史告警列表", "US-ASCII");
response.setHeader("content-disposition", "attachment;filename=" + fileName + ".xlsx");

response.setHeader('content-type','application/vnd.ms-excel;charset=UTF-8');
EasyExcel.write(response.getOutputStream(), AlarmWebsocketData.class).sheet("历史告警列表").doWrite(res);